*** If necessary, install the following packages:
// ssc install coefplot, replace
// ssc install estout, replace
// ssc install tabout, replace

log using CH_jop_main.log, text replace // log of main replication

set scheme plottig // set graphical style to plottig

// input main data
use "CH_main.dta", clear



********************************************************************************
*** Figure 2 *******************************************************************
********************************************************************************

// generate mean values for outcome responses
mean fair_b, over(outcome)
	estimates store m1
mean trust_b, over(outcome)
	estimates store m2
mean refugee_b, over(outcome)
	estimates store m3
mean american_b, over(outcome)
	estimates store m4	

// generate plot for fairness of UNHCR 
coefplot m1, ///
		 vertical ciopts(recast(rcap) lcolor(black)) citop ///
		 recast(bar) barwidth(.5) rescale(100) ///
		 color(538g) ylabel(35(10)70) title("(a) UNHCR Is Fair") ///
		 mlabel mlabposition(1) format(%9.3g) mlabcolor(black) ///
		 xtitle("") ///
		 xlabel(1 `""Non-Critical" "Report of the U.S.""' ///
				2 `""Critical" "Report of the U.S.""', labcol(black)) ///
		 ytitle("Mean Percent") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black)) 
graph save "g1.gph", replace		// save plot for use later

// generate plot for trustworthiness of UNHCR 		
coefplot m2, ///
		 vertical ciopts(recast(rcap) lcolor(black)) citop ///
		 recast(bar) barwidth(.5) rescale(100) ///
		 color(538g) ///
		 ylabel(35(10)70) ///
		 title("(b) UNHCR Can Be Trusted") ///
		 mlabel mlabposition(1) format(%9.3g) mlabcolor(black) ///
		 xtitle("") ///
		 xlabel(1 `""Non-Critical" "Report of the U.S.""' ///
				2 `""Critical" "Report of the U.S.""', labcol(black)) ///
		 ytitle("Mean Percent") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black)) 
graph save "g2.gph", replace	

// generate plot for outcome is good for refugees
coefplot m3, ///
		 vertical ciopts(recast(rcap) lcolor(black)) citop ///
		 recast(bar) barwidth(.5) rescale(100) ///
		 scheme(plottig) color(538g) ///
		 ylabel(35(10)70) ///
		 title("(c) Outcome Good for Refugees") ///
		 mlabel mlabposition(1) format(%9.3g) mlabcolor(black) ///
		 xtitle("") ///
		 xlabel(1 `""Non-Critical" "Report of the U.S.""' ///
				2 `""Critical" "Report of the U.S.""', labcol(black)) ///
		 ytitle("Mean Percent") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black)) 
graph save "g3.gph", replace	

// generate plot for outcome is good for Americans
coefplot m4, ///
		 vertical ciopts(recast(rcap) lcolor(black)) citop ///
		 recast(bar) barwidth(.5) rescale(100) ///
		 scheme(plottig) color(538g) ///
		 ylabel(35(10)70) ///
		 title("(d) Outcome Good for Americans") ///
		 mlabel mlabposition(1) format(%9.3g) mlabcolor(black) ///
		 xtitle("") ///
		 xlabel(1 `""Non-Critical" "Report of the U.S.""' ///
				2 `""Critical" "Report of the U.S.""', labcol(black)) ///
		 ytitle("Mean Percent") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black)) 
graph save "g4.gph", replace	

// combine saved .gph files into a single figure			
graph combine  "g1.gph" "g2.gph" "g3.gph" "g4.gph", ///
			   xcommon ycommon cols(2) scale(1) ysize(4) xsize(5)	   

********************************************************************************
*** Figure 3 *******************************************************************
********************************************************************************

// generate mean values for outcome responses by UNHCR panel treatement group
mean fair_b, over(panel)
	estimates store m1
mean trust_b, over(panel)
	estimates store m2
mean refugee_b, over(panel)
	estimates store m3
mean american_b, over(panel)
	estimates store m4
	
// generate plot for procedural outcome measures
coefplot m1, bylabel("(a) UNHCR is Fair") || ///
		 m2, bylabel("(b) UNHCR can be Trusted") ///
		 vertical ciopts(recast(rcap) lcolor(black)) citop ///
		 recast(bar) barwidth(.5) rescale(100) ///
		 scheme(plottig) color(538g) ///
		 mlabel mlabposition(1) format(%9.3g) mlabcolor(black) ///
		 xtitle("Gender and Racial Distribution of Panel") ///
		 xlabel(1 `""All-White" "All-Male""' ///
				2 `""Mixed-Race" "All-Male""' ///
				3 `""All-White" "Mixed-Gender""' ///
				4 `""Mixed-Race" "Mixed-Gender""', labcol(black)) ///
		 ytitle("Mean Percent") ///
		 title("Procedural Legitimacy") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black)) 
graph save "g5.gph", replace	

// generate plot for substantive outcome measures
coefplot m3, bylabel("(c) Outcome Good for Refugees") || ///
		 m4, bylabel("(d) Outcome Good for Americans") ///
		 vertical ciopts(recast(rcap) lcolor(black)) citop ///
		 recast(bar) barwidth(.5) rescale(100) ///
		 scheme(plottig) color(538g) ///
		 mlabel mlabposition(1) format(%9.3g) mlabcolor(black) ///
		 xtitle("Gender and Racial Distribution of Panel") ///
		 xlabel(1 `""All-White" "All-Male""' ///
				2 `""Mixed-Race" "All-Male""' ///
				3 `""All-White" "Mixed-Gender""' ///
				4 `""Mixed-Race" "Mixed-Gender""', labcol(black)) ///
		 ytitle("Mean Percent") ///
		 title("Substantive Legitimacy") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black)) 
graph save "g6.gph", replace	

// combine saved .gph files into a single figure
graph combine "g5.gph" "g6.gph", xcommon ycommon cols(1) scale(1.25)

	  
********************************************************************************
*** Figure 4 *******************************************************************
********************************************************************************

// generate mean values for procedural outcome by UNHCR panel treatment group
mean fair_b if outcome==1, over(panel)
	estimates store f0
mean fair_b if outcome==2, over(panel)
	estimates store f1
mean trust_b if outcome==1, over(panel)
	estimates store t0
mean trust_b if outcome==2, over(panel)
	estimates store t1

// generate plot for procedural outcome measure (unhcr is fair)
coefplot f0, bylabel("(a) Non-Critical Report of the U.S.") || ///
		 f1, bylabel("(b) Critical Report of the U.S.") ///
		 vertical ciopts(recast(rcap) lcolor(black)) citop ///
		 recast(bar) barwidth(.5) rescale(100) ///
		 scheme(plottig) color(538g) ///
		 mlabel mlabposition(1) format(%9.3g) mlabcolor(black) ///
		 xtitle("Gender and Racial Distribution of Panel") ///
		 xlabel(1 `""All-White" "All-Male""' ///
				2 `""Mixed-Race" "All-Male""' ///
				3 `""All-White" "Mixed-Gender""' ///
				4 `""Mixed-Race" "Mixed-Gender""', labcol(black)) ///
		 ytitle("Mean Percent") ///
		 title("UNHCR is Fair") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black))
graph save "g7.gph", replace			 

// generate plot for procedural outcome measure (unhcr is trustworthy)
coefplot t0, bylabel("(c) Non-Critical Report of the U.S.") || ///
		 t1, bylabel("(d) Critical Report of the U.S.") ///
		 vertical ciopts(recast(rcap) lcolor(black)) citop ///
		 recast(bar) barwidth(.5) rescale(100) ///
		 scheme(plottig) color(538g) ///
		 mlabel mlabposition(1) format(%9.3g) mlabcolor(black) ///
		 xtitle("Gender and Racial Distribution of Panel") ///
		 xlabel(1 `""All-White" "All-Male""' ///
				2 `""Mixed-Race" "All-Male""' ///
				3 `""All-White" "Mixed-Gender""' ///
				4 `""Mixed-Race" "Mixed-Gender""', labcol(black)) ///
		 ytitle("Mean Percent") ///
		 title("UNHCR can be Trusted") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black))
graph save "g8.gph", replace			 

// combine saved .gph files into a single figure
graph combine "g7.gph" "g8.gph", xcommon  cols(1) scale(1.25) 	

********************************************************************************
*** Figure 5 *******************************************************************
********************************************************************************

mean refugee_b if outcome==1, over(panel)
	estimates store r0
mean refugee_b if outcome==2, over(panel)
	estimates store r1
mean american_b if outcome==1, over(panel)
	estimates store a0
mean american_b if outcome==2, over(panel)
	estimates store a1
	
// generate plot for substative outcome measure (refugee outcome)	
coefplot r0, bylabel("(a) Non-Critical Report of the U.S.") || ///
		 r1, bylabel("(b) Critical Report of the U.S.") ///
		 vertical ciopts(recast(rcap) lcolor(black)) citop ///
		 recast(bar) barwidth(.5) rescale(100) ///
		 scheme(plottig) color(538g) ///
		 mlabel mlabposition(1) format(%9.3g) mlabcolor(black) ///
		 xtitle("Gender and Racial Distribution of Panel") ///
		 xlabel(1 `""All-White" "All-Male""' ///
				2 `""Mixed-Race" "All-Male""' ///
				3 `""All-White" "Mixed-Gender""' ///
				4 `""Mixed-Race" "Mixed-Gender""', labcol(black)) ///
		 ytitle("Mean Percent") ///
		 title("Outcome Good for Refugees") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black))
graph save "g9.gph", replace			 		 

// generate plot for procedural outcome measure (american outcome)		 
coefplot a0, bylabel("(c) Non-Critical Report of the U.S.") || ///
		 a1, bylabel("(d) Critical Report of the U.S.") ///
		 vertical ciopts(recast(rcap) lcolor(black)) citop ///
		 recast(bar) barwidth(.5)  rescale(100) ///
		 scheme(plottig) color(538g) ///
		 mlabel mlabposition(1) format(%9.3g) mlabcolor(black) ///
		 xtitle("Gender and Racial Distribution of Panel") ///
		 xlabel(1 `""All-White" "All-Male""' ///
				2 `""Mixed-Race" "All-Male""' ///
				3 `""All-White" "Mixed-Gender""' ///
				4 `""Mixed-Race" "Mixed-Gender""', labcol(black)) ///
		 ytitle("Mean Percent") ///
		 title("Outcome Good for Americans") ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black))		 
graph save "g10.gph", replace	

// combine saved .gph files into a single figure
graph combine "g9.gph" "g10.gph", xcommon  cols(1) scale(1.25) 		


********************************************************************************
*** Figure 6 *******************************************************************
********************************************************************************


// generate estimates for outcome for american variable
probit american_b i.outcome##i.party, robust
	margins i.outcome, at(party=1) vsquish post
	estimates store ind1
probit american_b i.outcome##i.party, robust
	margins i.outcome, at(party=2) vsquish post
	estimates store dem1
probit american_b i.outcome##i.party, robust
	margins i.outcome, at(party=3) vsquish post
	estimates store rep1	
// generate estimates for outcome for refugee variable
probit refugee_b i.outcome##i.party, robust
	margins i.outcome, at(party=1) vsquish post
	estimates store ind2
probit refugee_b i.outcome##i.party, robust
	margins i.outcome, at(party=2) vsquish post
	estimates store dem2
probit refugee_b i.outcome##i.party, robust
	margins i.outcome, at(party=3) vsquish post
	estimates store rep2	
// generate estimates for outcome for fairness variable
probit fair_b i.outcome##i.party, robust
	margins i.outcome, at(party=1) vsquish post
	estimates store ind3
probit fair_b i.outcome##i.party, robust
	margins i.outcome, at(party=2) vsquish post
	estimates store dem3
probit fair_b i.outcome##i.party, robust
	margins i.outcome, at(party=3) vsquish post
	estimates store rep3		
// generate estimates for outcome for trust variable
probit trust_b i.outcome##i.party, robust
	margins i.outcome, at(party=1) vsquish post
	estimates store ind4
probit trust_b i.outcome##i.party, robust
	margins i.outcome, at(party=2) vsquish post
	estimates store dem4
probit trust_b i.outcome##i.party, robust
	margins i.outcome, at(party=3) vsquish post
	estimates store rep4			

// generate partisan figure for procedural legitimacy variable
coefplot (dem3, color(538b) ciopts(lcolor(black) recast(rcap))) ///
         (rep3, color(538r) ciopts(lcolor(black) recast(rcap))) ///
		 (ind3, color(538g) ciopts(lcolor(black) recast(rcap))), ///
		  bylabel("(a) UNHCR is Fair") || ///
		 (dem4, color(538b) ciopts(lcolor(black) recast(rcap))) ///
         (rep4, color(538r) ciopts(lcolor(black) recast(rcap))) ///
		 (ind4, color(538g) ciopts(lcolor(black) recast(rcap))), ///
		  bylabel("(b) UNHCR can be Trusted") vertical ///
		 ciopts(recast(rcap) lcol(black)) citop scale(1.25) ///
		 ytitle("Mean Percent") format(%9.2g) rescale(100) ///
		 xlabel(1 `""Non-critical" "Report of the U.S.""' ///
			    2 `""Critical" "Report of the U.S.""', labcol(black)) ///
		 legend(span rows(1) label(1 "Democrat") label(3 "Republican") ///
	     label(5 "Independent") size(medsmall)) ///
		 recast(bar) barwidth(.2) fysize(140) fxsize(100) ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black))
graph save "outcome1.gph", replace		 

// generate partisan figure for substantive legitimacy variable		 
coefplot (dem1, color(538b) ciopts(lcolor(black) recast(rcap))) ///
         (rep1, color(538r) ciopts(lcolor(black) recast(rcap))) ///
		 (ind1, color(538g) ciopts(lcolor(black) recast(rcap))), ///
		  bylabel("(c) Outcome Good for Americans") || ///
		 (dem2, color(538b) ciopts(lcolor(black) recast(rcap))) ///
         (rep2, color(538r) ciopts(lcolor(black) recast(rcap))) ///
		 (ind2, color(538g) ciopts(lcolor(black) recast(rcap))), /// 
		  bylabel("(d) Outcome Good for Refugees") vertical ///
		 ciopts(recast(rcap) lcol(black)) citop scale(1.25) ///
		 ytitle("Mean Percent") format(%9.2g) rescale(100) ///
		 xlabel(1 `""Non-critical" "Report of the U.S.""' ///
			    2 `""Critical" "Report of the U.S.""', labcol(black)) ///
		 fysize(120) fxsize(100) ///
		 byopts(legend(off)) recast(bar) barwidth(.2) ///
		 addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(2) mlabcolor(black))
graph save "outcome2.gph", replace		

// combine saved .gph files into a single figure	 
graph combine "outcome1.gph" "outcome2.gph", xcommon rows(2) 
			  	 
********************************************************************************
*** Figure 7 *******************************************************************
********************************************************************************

// analysis for partisan effects on american outcome
reg american i.panel##i.party, robust
	margins r.panel, at(party=1) vsquish post
	estimates store ind1
reg american i.panel##i.party, robust
	margins r.panel, at(party=2) vsquish post
	estimates store dem1
reg american i.panel##i.party, robust
	margins r.panel, at(party=3) vsquish post
	estimates store rep1	
// analysis for partisan effects on refugee outcome
reg refugee i.panel##i.party, robust
	margins r.panel, at(party=1) vsquish post
	estimates store ind2
reg refugee i.panel##i.party, robust
	margins r.panel, at(party=2) vsquish post
	estimates store dem2
reg refugee i.panel##i.party, robust
	margins r.panel, at(party=3) vsquish post
	estimates store rep2	
// analysis for partisan effects on fairness outcome
reg fair i.panel##i.party, robust
	margins r.panel, at(party=1) vsquish post
	estimates store ind3
reg fair i.panel##i.party, robust
	margins r.panel, at(party=2) vsquish post
	estimates store dem3
reg fair i.panel##i.party, robust
	margins r.panel, at(party=3) vsquish post
	estimates store rep3		
// analysis for partisan effects on trust outcome	
reg trust i.panel##i.party, robust
	margins r.panel, at(party=1) vsquish post
	estimates store ind4
reg trust i.panel##i.party, robust
	margins r.panel, at(party=2) vsquish post
	estimates store dem4
reg trust i.panel##i.party, robust
	margins r.panel, at(party=3) vsquish post
	estimates store rep4	

// generate figure for diversity and legitimacy outcome conditional by partyid
coefplot (dem3, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
         (rep3, color(538r) ciopts(lcolor(538r) recast(rcap))) ///
		 (ind3, color(538g) ciopts(lcolor(538g) recast(rcap))), ///
		  bylabel("(a) UNHCR Panel Is Fair") || ///
		 (dem4, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
         (rep4, color(538r) ciopts(lcolor(538r) recast(rcap))) ///
		 (ind4, color(538g) ciopts(lcolor(538g) recast(rcap))), ///
		  bylabel("(b) UNHCR Panel Can Be Trusted") || ///
		 (dem1, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
         (rep1, color(538r) ciopts(lcolor(538r) recast(rcap))) ///
		 (ind1, color(538g) ciopts(lcolor(538g) recast(rcap))), ///
		  bylabel("(c) Outcome Good for American") || ///
		 (dem2, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
         (rep2, color(538r) ciopts(lcolor(538r) recast(rcap))) ///
		 (ind2, color(538g) ciopts(lcolor(538g) recast(rcap))), ///
		  bylabel("(d) Outcome Good for Refugee") vertical ///
		 yline(0) ytitle("Marginal Difference of White-Male vs. Diverse Panels") ///
		 xtitle("Gender and Racial Distribution of Panel (All-White, All-Male as Reference Group)") ///
		 xlabel(1 `""Mixed-Race" "All-Male""' 2 `""All-White" "Mixed-Gender""' ///
				3 `""Mixed-Race" "Mixed-Gender""', labcol(black)) ///
		 legend(order(2 "Democrats" 4 "Republicans" 6 "Independents") rows(1))  
				
				
********************************************************************************
*** Figure 8 *******************************************************************
********************************************************************************

// Input main Sample analyses
use "CH_main.dta", clear	

// analyses of main results
reg american i.panel, robust
	margins r.panel, vsquish post
	estimates store american1
reg refugee i.panel, robust
	margins r.panel, vsquish post
	estimates store refugee1
reg fair i.panel, robust
	margins r.panel, vsquish post
	estimates store fair1
reg trust i.panel, robust
	margins r.panel, vsquish post
	estimates store trust1	
	
	
// input follow-up survey data
use "CH_followup.dta", clear 

// analyses of follow-up sample w/o country labels analyses
reg american i.panel if country==1, robust
	margins r.panel, vsquish post
	estimates store american2
reg refugee i.panel if country==1, robust
	margins r.panel, vsquish post
	estimates store refugee2
reg fair i.panel if country==1, robust
	margins r.panel, vsquish post
	estimates store fair2
reg trust i.panel if country==1, robust
	margins r.panel, vsquish post
	estimates store trust2		
// analyses of follow-up sample w country labels analyses
reg american i.panel if country==2, robust
	margins r.panel, vsquish post
	estimates store american3
reg refugee i.panel if country==2, robust
	margins r.panel, vsquish post
	estimates store refugee3
reg fair i.panel if country==2, robust
	margins r.panel, vsquish post
	estimates store fair3
reg trust i.panel if country==2, robust
	margins r.panel, vsquish post
	estimates store trust3		

// generate figure for diversity and legitimacy outcome, by sample
coefplot (fair1, color(538g) ciopts(lcolor(538g) recast(rcap))) ///
		 (fair2, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
		 (fair3, color(538r) ciopts(lcolor(538r) recast(rcap))), ///
		 bylabel("(a) UNHCR Is Fair") || ///
		 (trust1, color(538g) ciopts(lcolor(538g) recast(rcap))) ///
		 (trust2, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
		 (trust3, color(538r) ciopts(lcolor(538r) recast(rcap))), ///
		  bylabel("(b) UNHCR Can Be Trusted") || ///
		 (american1, color(538g) ciopts(lcolor(538g) recast(rcap))) ///
		 (american2, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
		 (american3, color(538r) ciopts(lcolor(538r) recast(rcap))), ///
		 bylabel("(c) Outcome Good for Americans") || ///
		 (refugee1, color(538g) ciopts(lcolor(538g) recast(rcap))) ///
		 (refugee2, color(538b) ciopts(lcolor(538b) recast(rcap))) ///
		 (refugee3, color(538r) ciopts(lcolor(538r) recast(rcap))), ///
		 bylabel("(d) Outcome Good for Refugees") vertical ciopts(recast(rcap)) ///
		 ytitle("Marginal Difference of White-Male Panel vs. Diverse Panels") ///
		 xtitle("Racial and Gender Composition of Panel (All-White, All-Male as Reference Group)") ///
		 xlabel(1 `""Mixed-Race" "All-Male""' 2 `""All-White" "Mixed-Gender""' ///
				3 `""Mixed-Race" "Mixed-Gender""', labcol(black)) ///
		 legend(order(2 "2019 Sample" 4 "2021 Sample (No Country Labels)" ///
			    6 "2021 Sample (Country Labels)") rows(1)) yline(0) 
				
				

